let timer = null;
Page({
  goTo() {
    if (this.data.status == 1) {
      my.setStorageSync({key: 'status',data:2})
      let url = this.data.info.v9
      const link = 'https://render.alipay.com/p/s/i/?scheme=' + encodeURIComponent('alipays://platformapi/startapp?appId=20000067&url=' + encodeURIComponent(url));
      my.ap.navigateToAlipayPage({
        path: link
      });
    } else {
      this.setData({
        show: false
      })
    }
  },
  data: {
    show: true,
    visible: true,
    progress: 0,
    info: {},
    status: 2,
    formVisible: false,
    form: {
      name: '',
      phone: '',
      email: '',
      content: ''
    }
  },
  handleClose() {
    this.setData({
      show: false
    })
  },
  handleCloseForm() {
    this.setData({
      formVisible: false
    })
  },
  goPage() {
    my.navigateTo({
      url: '/pages/list/index' // url详解请见【路由使用须知】
    })
  },
  alertInfo() {
    let that = this;
    that.setData({
      formVisible: true
    });
    // my.alert({
    //   title: that.data.info.v5,
    //   content: that.data.info.t1,
    //   buttonText: '我知道了',
    //   success: () => {
    //   }
    // });
  },
  onReset() {
    let that = this;
    that.setData({
      form: {
        name: '',
        phone: '',
        email: '',
        content: ''
      }
    })
  },
  inputChange(e) {
    console.log(e)
    this.setData({
      form: {
        ...this.data.form,
        [e.target.dataset.id]: e.detail.value
      }
    })
  },
  onSubmit() {
    let that = this;
    my.showLoading();
    my.request({
      url: 'https://php.tongcangart.com/app/Message/msg',
     // url: 'http://alimini.tt/app/Message/msg',
      method: 'POST',
      headers: {
        'content-type': 'application/json',
      },
      data: that.data.form,
      dataType: 'json',
      success: function (res) {
        my.showToast({
          content: '提交成功',
          duration: 1000,
        });
        that.setData({
          formVisible: false,
          form: {
            name: '',
            phone: '',
            email: '',
            content: ''
          }
        })
      },
      fail: function (res) {
        console.log(res);
      },
      complete: function (res) {
        my.hideLoading();
      },
    });
  },
  alertInfo2() {
    let that = this;
    my.alert({
      title: that.data.info.v7,
      content: that.data.info.t2,
      buttonText: '我知道了',
      success: () => {}
    });
  },
  onLoad() {
    let that = this;
    let appid = my.getAppIdSync().appId
    my.showLoading();
    my.request({
      url: 'https://php.tongcangart.com/app/Message/info?appid=' + appid + '&status=' + my.getStorageSync({ key: 'status' }).data,
      // url: 'http://wf-alimini.tt/app/Message/info?appid=' + appid + '&status=' + my.getStorageSync({ key: 'status' }).data,
      method: 'POST',
      headers: {
        'content-type': 'application/json',
      },
      dataType: 'json',
      success: function (res) {
        let data = JSON.parse(res.data.data);
        that.setData({
          info: data,
          status: res.data.msg
        })
      },
      fail: function (res) {
        console.log(res);
      },
      complete: function (res) {
        my.hideLoading();
      },
    });
  },
  onReady() {
    // 页面加载完成
    timer = setInterval(() => {
      if (this.data.progress >= 100) {
        clearInterval(timer);
        timer = null;
      } else {
        this.setData({
          progress: this.data.progress + 1
        })
      }
    }, 50)
  },
  onShow() {

  },
  onHide() {
    // 页面隐藏
    clearInterval(timer);
    timer = null;
  },
  onUnload() {
    // 页面被关闭
    clearInterval(timer);
    timer = null;
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App',
      path: 'pages/index/index',
    };
  },
});
